<?php
/**
 * Created by PhpStorm.
 * User: jiangjunxian
 * Date: 2016/12/2
 * Time: 14:47
 */

namespace app\modules\admin\widgets\gird;

use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\widgets\LinkPager;

class GridWidget extends GridView
{
    public $title = '';
    public $toolButtons = [];
    public $pager = ['options'=>['class'=>'pagination pagination-sm no-margin pull-right']];
    public $tableOptions = [ 'class' => 'table table-hover table-bordered' ];
    public $layout = <<<str
<div class="box box-success">
    <div class="box-header">
        <h3 class="box-title">{title}</h3>
        {toolButtons}
    </div>
    <div class="box-body">
        {items}
    </div>
    <div class="box-footer">
    <div class="row">
        <div class="col-sm-5">{summary}</div>
        <div class="col-sm-7">{pager}</div>
    </div>
    </div>
</div>
str;

    private function renderLayout() {
        $str = $this->layout;
        $str = str_replace('{title}', $this->title, $str);

        if(!empty($this->toolButtons)) {
            $tpl = '<div class="pull-right">';
            foreach ($this->toolButtons as $button) {
                $tpl .= $button;
            }
            $tpl .= '</div>';
            $str = str_replace('{toolButtons}', $tpl, $str);
        } else {
            $str = str_replace('{toolButtons}', '', $str);
        }
        return $str;
    }

    public function run()
    {
        $this->layout = $this->renderLayout();
        parent::run();
    }


}